// [2302]${question.tilte}
struct Solution;

//leetcode submit region begin(Prohibit modification and deletion)
impl Solution {
    pub fn count_subarrays(nums: Vec<i32>, k: i64) -> i64 {
        let mut result = 0i64;
        let mut i = 0i64;
        let mut total = 0i64;
        for j in 0..nums.len() {
            total += nums[j] as i64;
            while i <= j as i64 && total * (j as i64 - i + 1) >= k {
                total -= nums[i as usize] as i64;
                i += 1;
            }
            result += j as i64 - i + 1;
        }
        result
    }
}
//leetcode submit region end(Prohibit modification and deletion)

#[test]
fn main() {
    let nums = vec![2, 1, 4, 3, 5];
    let k = 10;
    assert_eq!(Solution::count_subarrays(nums, k), 6);
    let nums = vec![1, 1, 1];
    let k = 5;
    assert_eq!(Solution::count_subarrays(nums, k), 5);
}
